package com.gxuwz.controller;

import com.gxuwz.entity.User;
import com.gxuwz.entity.WebResult;
import com.gxuwz.service.IUserService;
import com.gxuwz.util.WebResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by h on 2017/11/22.
 */
@RestController
public class UserController {

    private static final Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private IUserService userService;

    @PostMapping(value = "/users")
    public WebResult<User> insert(User user){
        return WebResultUtil.success(userService.save(user));
    }

    @PutMapping(value = "/users/{id}")
    public User update(User user){
        return userService.update(user);
    }

    @DeleteMapping(value = "/users/{id}")
    public void delete(@PathVariable("id") String id){
        userService.delete(id);
    }

    @GetMapping(value = "/users/{id}")
    public WebResult<User> findOne(@PathVariable("id") String id){
        return WebResultUtil.success(userService.findOne(id));
    }

    @GetMapping(value = "/users")
    public List<User> findAll(){
        return userService.findAll();
    }

}
